package com.example.demo.controller;

import com.example.demo.entity.DTO.UpdatePropDTO;
import com.example.demo.entity.VO.pet.PropVO;
import com.example.demo.service.PropService;
import com.example.demo.wrapper.Result;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1")
public class propController {

    private final PropService propService;

    public propController(PropService propService) {

        this.propService = propService;
    }

    @GetMapping("/user/{userId}/prop")
    public Result<List<PropVO>> getProps(@PathVariable(value = "userId") Integer userId,
                                         @RequestParam(value = "type", required = false) String type){
        return Result.buildSuccess(propService.getPropsByUserId(userId, type));
    }

    @PutMapping("/user/{userId}/prop")
    public Result<Void> updatePropAmount(@PathVariable(value = "userId") Integer userId,
                                         @RequestBody List<UpdatePropDTO> updatePropDTOList){
        propService.updatePropAmount(updatePropDTOList, userId);

        return Result.buildSuccess();
    }
}
